package org.jw.wishlist.service.impl;

import static org.jw.wishlist.config.ItemSourceResolverAutoConfiguration.REST_TEMPLATE_NAME;

import org.jw.wishlist.entity.source.ItemSource;
import org.jw.wishlist.resolver.ItemSourceResolverFactory;
import org.jw.wishlist.service.ItemSourceResolvingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @author Jiawei Zhao
 */
@Service
public class ItemSourceResolvingServiceImpl implements ItemSourceResolvingService {

  private final RestTemplate restTemplate;

  @Autowired
  public ItemSourceResolvingServiceImpl(@Qualifier(REST_TEMPLATE_NAME) RestTemplate restTemplate) {
    this.restTemplate = restTemplate;
  }

  @Override
  public ItemSource resolve(String linkCode) {
    return new ItemSourceResolverFactory(linkCode, restTemplate).getResolver().resolve(linkCode);
  }

}
